import 'package:flutter/material.dart';

///todo:左边字体，右边图标，左右两边对齐样式
class TextIconRow extends StatefulWidget {
  //左边字体
  String leftText;
  //右边图标
  IconData rightIcon;
  //左边字体颜色
  Color leftTextColor;
  //右边图标颜色
  Color rightIconColor;
  //整行的颜色设置
  Color rowColor;
  //右边图标大小
  double rightIconSize;
  //左边字体大小
  double leftTextSize;
  //整行的点击事件
  VoidCallback onTap;
  //整行的高度
  double height;
  //字体外边距设置
  double textMarginLeft; //左外边距
  //图标外边距设置
  double iconMarginRight; //左外边距

  TextIconRow({
    Key key,
    this.leftText,
    this.rightIcon,
    this.leftTextColor: Colors.black,
    this.rightIconColor: Colors.black12,
    this.rowColor: Colors.black12,
    this.rightIconSize: 25,
    this.leftTextSize: 15,
    this.height: 50.0,
    this.onTap,
    this.textMarginLeft: 10,
    this.iconMarginRight: 10,
  }) : super(key: key);

  @override
  _TextIconRowState createState() => _TextIconRowState();
}

class _TextIconRowState extends State<TextIconRow> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: widget.onTap, //整行的点击事件
      child: Container(
        padding: EdgeInsets.only(
            left: widget.textMarginLeft, right: widget.iconMarginRight),
        width: MediaQuery.of(context).size.width, //获取屏幕宽度
        height: widget.height, //整行的高度
        color: widget.rowColor,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween, //设置两边分隔
          children: <Widget>[
            //左边字体
            InkWell(
                child: Container(
//                  margin: EdgeInsets.fromLTRB(widget.textMarginLeft, 0, 0, 0),
                  child: Row(
                    children: <Widget>[
                      Container(
//                        alignment: Alignment.centerLeft,
                        child: Text(
                          widget.leftText,
                          style: TextStyle(
                              color: widget.leftTextColor,
                              fontSize: widget.leftTextSize),
//                          textAlign: TextAlign.center,
                        ),
                      ),
                    ],
                  ),
                )),
            //右边图标
            InkWell(
              child: Container(
//                margin: EdgeInsets.fromLTRB(0, 0, widget.iconMarginRight, 0),
                child: Row(
                  children: <Widget>[
                    //小图标
                    Container(
//                      alignment: Alignment.centerRight,
                      child: Icon(
                        widget.rightIcon,
                        color: widget.rightIconColor,
                        size: widget.rightIconSize,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
